import 'element-plus/dist/index.css'
import './assets/css/main.css'


import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'

const app = createApp(App)

declare module 'vue' {
  interface ComponentCustomProperties {
    $baseAdminUrl: string;
    $authorization:string;
    $resolvPath: (path: string) => string;
  }
}

const baseAdminUrl = import.meta.env.VITE_API_ADMIN_URL
app.config.globalProperties.$baseAdminUrl = baseAdminUrl

app.config.globalProperties.$authorization = `Bearer ${localStorage.getItem('gx-token')}`

app.config.globalProperties.$resolvPath = (path: string) => {
  if (!path)return '';
  return path.startsWith('http')? path : baseAdminUrl + path;
}

app.use(createPinia())
app.use(router)

// 安装element-plus插件
import ElementPlus from 'element-plus'

app.use(ElementPlus)

// 注册element-plus所有的图标组件
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 注册自定义组件
import GxUI from './components/GxUI'
app.use(GxUI)

app.mount('#app')
